$(function(){
    obj.init();
});

var obj = new JsFun();
function JsFun(){
    'use strict';
    return {
        dom: {
            btnView: null,
            frame: null,
            school: null,
            month: null
        },
        init: function () {
            this.dom.btnView = $('#bt_view_usage');
            this.dom.frame   = $('iframe');
            this.dom.school  = $('#schoolId');
            this.dom.month   = $('#target_month');

            this.dom.school.select2();

            this.listener();
        },
        listener: function () {
            var $this = this;
            //点击查询
            $this.dom.btnView.click(function () {
                $this.funObj().viewUsage();
            });
        },
        funObj: function(){
            var $this = this;
            return {
                viewUsage: function () {
                    $this.dom.frame.attr('src', '');
                    setTimeout(function () {
                        var schoolId    = $this.dom.school.val();
                        var targetMonth = $this.dom.month.val();
                        if (!schoolId) {
                            window.top.xhTop.showError('学校为必选项！');
                            return false;
                        }
                        if (!targetMonth) {
                            window.top.xhTop.showError('月份不能为空！');
                            return false;
                        }
                        $this.dom.frame.attr('src', baseUrl + 'Statsbook/info?' + xhTool.parseParam({schoolId: schoolId, targetMonth: targetMonth}));
                        window.top.xhTop.showSuccess('统计执行中！请耐心等待！');
                    }, 0);
                }
            }
        }
    }
}